03. Video + Quiz: Write Your First Subquery
Your First Subquery
Your First Subquery
The first time you write a subquery it might seem really complex. Let's try breaking it down into its different parts.
If you get stuck look again at the video above. We want to find the average number of events for each day for each channel. The first table will provide us the number of events for each day and channel, and then we will need to average these values together using a second query.
You try solving this yourself.
Task Description:
Tasks to complete.
Task Feedback:
Nice job! Understanding how to nest one query within another query is key to answering many questions that pertain to any company storing data in a relational database.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: sql-evaluator
- Opened files (when workspace is loaded): n/a
SOLUTION:
- January 1, 2017; direct
- December 21, 2016; direct
SOLUTION:
- The original query goes in the **FROM** statement.
- An `*` is used in the **SELECT** statement to pull all of the data from the original query.
- You **MUST** use an alias for the table you nest within the outer query.
QUIZ QUESTION::
Match each channel to its corresponding average number of events per day.
ANSWER CHOICES:
Channel |
Average Number of Events/Day |
---|---|
1.60 |
|
1.67 |
|
4.90 |
|
1.32 |
SOLUTION:
Channel |
Average Number of Events/Day |
---|---|
1.60 |
|
1.67 |
|
4.90 |
|
1.32 |